﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using YArchitech.LIB;
using QuickModel.CommonTrans;

namespace QuickModel.Forms
{
	public partial class QuickModelMainForm : System.Windows.Forms.Form
	{
		public QuickModelMainForm(QuickModelMainRequestMaker marker)
		{
			this.InitializeComponent();
			this.m_lstWallLayer = new List<string>();
			this.m_lstColumnLayer = new List<string>();
			this.m_lstWindowLayer = new List<string>();
			this.m_lstWindowNumberLayer = new List<string>();
			this.m_DlgCloseType = QuickModelMainForm.CloseDlgType.RT_Otheer;
			this.m_marker = marker;
			this.m_btnToolTip = new ToolTip();
			this.m_btnToolTip.AutomaticDelay = 500;
			this.LoadSelectedLayers();
		}

		public QuickModelMainForm.CloseDlgType DlgCloseType
		{
			get
			{
				return this.m_DlgCloseType;
			}
		}

		public List<string> WallLayers
		{
			get
			{
				return this.m_lstWallLayer;
			}
		}

		public List<string> ColumnLayers
		{
			get
			{
				return this.m_lstColumnLayer;
			}
		}

		public List<string> WindowLayers
		{
			get
			{
				return this.m_lstWindowLayer;
			}
		}

		public List<string> WindowNumberLayers
		{
			get
			{
				return this.m_lstWindowNumberLayer;
			}
		}

		public bool AddWallLayer(string strLayer)
		{
			bool flag = string.IsNullOrWhiteSpace(strLayer) || this.m_lstWallLayer.Contains(strLayer);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.m_lstWallLayer.Add(strLayer);
				string text = "已选择图层：\n";
				for (int i = 0; i < this.m_lstWallLayer.Count; i++)
				{
					text = text + this.m_lstWallLayer[i] + "\n";
				}
				this.m_btnToolTip.SetToolTip(this.btnSelectWall, text);
				result = true;
			}
			return result;
		}

		public bool AddColumnLayer(string strLayer)
		{
			bool flag = string.IsNullOrWhiteSpace(strLayer) || this.m_lstColumnLayer.Contains(strLayer);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.m_lstColumnLayer.Add(strLayer);
				string text = "已选择图层：\n";
				for (int i = 0; i < this.m_lstColumnLayer.Count; i++)
				{
					text = text + this.m_lstColumnLayer[i] + "\n";
				}
				this.m_btnToolTip.SetToolTip(this.btnSelectColumn, text);
				result = true;
			}
			return result;
		}

		public bool AddWindowLayer(string strLayer)
		{
			bool flag = string.IsNullOrWhiteSpace(strLayer) || this.m_lstWindowLayer.Contains(strLayer);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.m_lstWindowLayer.Add(strLayer);
				string text = "已选择图层：\n";
				for (int i = 0; i < this.m_lstWindowLayer.Count; i++)
				{
					text = text + this.m_lstWindowLayer[i] + "\n";
				}
				this.m_btnToolTip.SetToolTip(this.btnSelectWindow, text);
				result = true;
			}
			return result;
		}

		public bool AddWindowNumberLayer(string strLayer)
		{
			bool flag = string.IsNullOrWhiteSpace(strLayer) || this.m_lstWindowNumberLayer.Contains(strLayer);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.m_lstWindowNumberLayer.Add(strLayer);
				string text = "已选择图层：\n";
				for (int i = 0; i < this.m_lstWindowNumberLayer.Count; i++)
				{
					text = text + this.m_lstWindowNumberLayer[i] + "\n";
				}
				this.m_btnToolTip.SetToolTip(this.btnSelectWindowNumber, text);
				result = true;
			}
			return result;
		}

		private void SetFormItemStyle()
		{
			this.labelSelectedWall.Text = string.Format("已选择 {0} 个参考图元", this.m_lstWallLayer.Count);
			this.labelSelectedColumn.Text = string.Format("已选择 {0} 个参考图元", this.m_lstColumnLayer.Count);
			this.labelSelectedWindow.Text = string.Format("已选择 {0} 个参考图元", this.m_lstWindowLayer.Count);
			this.labelSelectedWindowNumber.Text = string.Format("已选择 {0} 个参考图元", this.m_lstWindowNumberLayer.Count);
			this.pictSelectWallOk.Visible = (this.m_lstWallLayer.Count > 0);
			this.pictSelectColumnOk.Visible = (this.m_lstColumnLayer.Count > 0);
			this.pictSelectWindowOk.Visible = (this.m_lstWindowLayer.Count > 0);
			this.pictSelectWindowNumberOk.Visible = (this.m_lstWindowNumberLayer.Count > 0);
			this.labelSelectedWall.ForeColor = ((this.m_lstWallLayer.Count > 0) ? System.Drawing.Color.Green : System.Drawing.Color.Black);
			this.labelSelectedColumn.ForeColor = ((this.m_lstColumnLayer.Count > 0) ? System.Drawing.Color.Green : System.Drawing.Color.Black);
			this.labelSelectedWindow.ForeColor = ((this.m_lstWindowLayer.Count > 0) ? System.Drawing.Color.Green : System.Drawing.Color.Black);
			this.labelSelectedWindowNumber.ForeColor = ((this.m_lstWindowNumberLayer.Count > 0) ? System.Drawing.Color.Green : System.Drawing.Color.Black);
			this.btnTransLevel.Enabled = (this.m_lstWallLayer.Count > 0 || this.m_lstColumnLayer.Count > 0 || this.m_lstWindowLayer.Count > 0);
			this.btnTransLocal.Enabled = (this.m_lstWallLayer.Count > 0 || this.m_lstColumnLayer.Count > 0 || this.m_lstWindowLayer.Count > 0);
		}

		private void LoadSelectedLayers()
		{
		}

		private void SaveSelectedLayers()
		{
		}

		private void ReadNodeLayers(XmlElement root, string strNodeName, List<string> lstLayer)
		{
			XmlNode xmlNode = root.SelectSingleNode(strNodeName);
			bool flag = xmlNode == null;
			if (!flag)
			{
				foreach (object obj in xmlNode.ChildNodes)
				{
					XmlNode xmlNode2 = (XmlNode)obj;
					XmlElement xmlElement = xmlNode2 as XmlElement;
					string attribute = xmlElement.GetAttribute("图层名称");
					lstLayer.Add(attribute);
				}
			}
		}

		private void WriteNodeLayers(XmlDocument xmlDoc, string strNodeName, List<string> lstLayer)
		{
			XmlElement documentElement = xmlDoc.DocumentElement;
			XmlNode xmlNode = xmlDoc.CreateElement(strNodeName);
			bool flag = xmlNode == null;
			if (!flag)
			{
				foreach (string innerText in lstLayer)
				{
					XmlNode xmlNode2 = xmlDoc.CreateElement("图层");
					XmlAttribute xmlAttribute = xmlDoc.CreateAttribute("图层名称");
					xmlAttribute.InnerText = innerText;
					xmlNode2.Attributes.Append(xmlAttribute);
					xmlNode.AppendChild(xmlNode2);
				}
				documentElement.AppendChild(xmlNode);
			}
		}

		private void QuickModelMainForm_Load(object sender, EventArgs e)
		{
			base.Icon = Resource.YArchitechIcon;
			this.SetFormItemStyle();
		}

		private void btnSelectWall_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = QuickModelMainForm.CloseDlgType.RT_SelectWallLine;
			base.DialogResult = DialogResult.OK;
		}

		private void btnSelectColumn_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = QuickModelMainForm.CloseDlgType.RT_SelectColumnLine;
			base.DialogResult = DialogResult.OK;
		}

		private void btnSelectWindow_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = QuickModelMainForm.CloseDlgType.RT_SelectWindow;
			base.DialogResult = DialogResult.OK;
		}

		private void btnSelectWindowNumber_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = QuickModelMainForm.CloseDlgType.RT_SelectWindowNumber;
			base.DialogResult = DialogResult.OK;
		}

		private void pictClearWall_Click(object sender, EventArgs e)
		{
			this.m_lstWallLayer.Clear();
			this.m_marker.ClearSelectedWall();
			this.SetFormItemStyle();
			this.m_btnToolTip.SetToolTip(this.btnSelectWall, null);
		}

		private void pictClearColumn_Click(object sender, EventArgs e)
		{
			this.m_lstColumnLayer.Clear();
			this.m_marker.ClearSelectedColumn();
			this.SetFormItemStyle();
			this.m_btnToolTip.SetToolTip(this.btnSelectColumn, null);
		}

		private void pictClearWindow_Click(object sender, EventArgs e)
		{
			this.m_lstWindowLayer.Clear();
			this.m_marker.ClearSelectedWindow();
			this.SetFormItemStyle();
			this.m_btnToolTip.SetToolTip(this.btnSelectWindow, null);
		}

		private void pictClearWindowNumber_Click(object sender, EventArgs e)
		{
			this.m_lstWindowNumberLayer.Clear();
			this.m_marker.ClearSelectedWindowNumber();
			this.SetFormItemStyle();
			this.m_btnToolTip.SetToolTip(this.btnSelectWindowNumber, null);
		}

		private void pictSetup_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = QuickModelMainForm.CloseDlgType.RT_SetupParam;
			base.DialogResult = DialogResult.OK;
		}

		private void btnTransLevel_Click(object sender, EventArgs e)
		{
			this.SaveSelectedLayers();
			this.m_DlgCloseType = QuickModelMainForm.CloseDlgType.RT_TransForLevel;
			base.DialogResult = DialogResult.OK;
		}

		private void btnTransLocal_Click(object sender, EventArgs e)
		{
			this.SaveSelectedLayers();
			this.m_DlgCloseType = QuickModelMainForm.CloseDlgType.RT_TransForLocal;
			base.DialogResult = DialogResult.OK;
		}

		private void QuickModelMainForm_KeyDown(object sender, KeyEventArgs e)
		{
			bool flag = e.KeyCode == Keys.Escape;
			if (flag)
			{
				base.DialogResult = DialogResult.Cancel;
			}
		}

		private List<string> m_lstWallLayer;

		private List<string> m_lstColumnLayer;

		private List<string> m_lstWindowLayer;

		private List<string> m_lstWindowNumberLayer;

		private string m_strXmlFile = Path.Combine(Product.UserDataLocation, "主体快模.xml");

		private QuickModelMainForm.CloseDlgType m_DlgCloseType;

		private QuickModelMainRequestMaker m_marker;

		private ToolTip m_btnToolTip;

		public enum CloseDlgType
		{
			RT_Otheer,
			RT_SetupParam,
			RT_SelectWallLine,
			RT_SelectColumnLine,
			RT_SelectWindow,
			RT_SelectWindowNumber,
			RT_TransForLevel,
			RT_TransForLocal
		}
	}
}
